package com.bins.charts.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateUtil {

    public static String getYearMonthString(int number) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(2, number);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(calendar.getTime()).substring(0, 7);
    }

    public static String getDateString(Date date) {
        DateFormat df = getNewDateFormat("yyyyMMdd");
        return df.format(date);
    }

    public static DateFormat getNewDateFormat(String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        df.setLenient(false);
        return df;
    }

    public static void main(String[] args) {
        Integer nowMonth = Integer.parseInt(DateUtil.getDateString(new Date()).substring(4, 6));
        System.out.println(nowMonth);
        List<String> monthList = Arrays.asList("2", "3", "4", "5", "6", "7");
        int size = monthList.size();
        System.out.println(size);
        for (int i = 0; i < monthList.size(); i++) {
            System.out.println(getYearMonthString(i - size + 1));
        }

    }
}
